package com.toocms.jinjuhang.ui.commodity.classify

import android.view.View
import android.view.inputmethod.EditorInfo
import com.blankj.utilcode.util.KeyboardUtils
import com.toocms.jinjuhang.R
import com.toocms.jinjuhang.BR
import com.toocms.jinjuhang.databinding.FgtClassifyCommodityListBinding
import com.toocms.jinjuhang.ui.base.BaseFgt
import com.toocms.tab.TooCMSApplication

class ClassifyCommodityListFgt :
    BaseFgt<FgtClassifyCommodityListBinding, ClassifyCommodityListModel>() {
    override fun onFragmentCreated() {
        topBar.visibility = View.GONE
        binding.inputEdt.setOnEditorActionListener { v, actionId, event ->
            if (EditorInfo.IME_ACTION_SEARCH != actionId) return@setOnEditorActionListener false
            viewModel.keyword = binding.inputEdt.text.toString()
            KeyboardUtils.hideSoftInput(v)
            return@setOnEditorActionListener true
        }
    }

    override fun getLayoutResId() = R.layout.fgt_classify_commodity_list

    override fun getVariableId() = BR.classifyCommodityListModel

    override fun viewObserver() {
        viewModel.stopRefreshOrLoadSingleLiveEvent.observe(this) {
            binding.refreshSrl.finishRefresh()
            binding.refreshSrl.finishLoadMore()
        }
    }

    override fun getViewModel() =
        ClassifyCommodityListModel(TooCMSApplication.getInstance(), requireArguments())

}